<template>
  <div class="app-container">
    <!-- 高级查询 -->
    <el-form v-show="searchVisible" ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item label="容器号 :">
        <el-input v-model="queryParams.contianBoxNo" size="small" placeholder="请输入容器号 " clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="要求出库时间:">
        <el-date-picker v-model="queryParams.requstRecptDate" type="date" value-format="yyyy-MM-dd" size="small" placeholder="选择要求出库时间" clearable />
      </el-form-item>
      <el-form-item label="库位号 :">
        <el-input v-model="queryParams.locationNo" size="small" placeholder="请输入库位号 " clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.materialName" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label=":">
        <el-input v-model="queryParams.customerName" size="small" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="数量:">
        <el-input v-model="queryParams.qty" size="small" placeholder="请输入数量" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="入库计划明细号:">
        <el-input v-model="queryParams.reciptLineId" size="small" placeholder="请输入入库计划明细号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="上架序号:">
        <el-input v-model="queryParams.seqNo" size="small" placeholder="请输入上架序号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="创建时间:">
        <el-date-picker v-model="queryParams.createTime" type="date" placeholder="选择创建时间" />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWmsReciptIntoLocPlan:insert']" type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWmsReciptIntoLocPlan:update']" type="success" icon="el-icon-edit" size="mini" :disabled="isSingle" @click="handleEdit">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWmsReciptIntoLocPlan:delete']" type="danger" icon="el-icon-delete" size="mini" :disabled="isMultiple" @click="handleRemove">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button v-hasPermission="['web:tWmsReciptIntoLocPlan:export']" type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="searchVisible" @queryTable="handleQuery" />
    </el-row>

    <!-- 数据列表 -->
    <el-table v-loading="loading" :data="page.records" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="容器号 " align="center" prop="contianBoxNo" />
      <el-table-column label="要求出库时间" align="center" prop="requstRecptDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.requstRecptDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="库位号 " align="center" prop="locationNo" />
      <el-table-column label="" align="center" prop="materialName" />
      <el-table-column label="" align="center" prop="customerName" />
      <el-table-column label="数量" align="center" prop="qty" />
      <el-table-column label="入库计划明细号" align="center" prop="reciptLineId" />
      <el-table-column label="上架序号" align="center" prop="seqNo" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-hasPermission="['web:tWmsReciptIntoLocPlan:update']" size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">修改</el-button>
          <el-button v-hasPermission="['web:tWmsReciptIntoLocPlan:delete']" size="mini" type="text" icon="el-icon-delete" @click="handleRemove(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="page.total>0" :total="page.total" :page.sync="page.current" :limit.sync="page.pageSize" @pagination="handleQuery" />

    <!-- 添加/修改对话框 -->
    <el-dialog :title="tWmsReciptIntoLocPlanFormDialog.title" :visible.sync="tWmsReciptIntoLocPlanFormDialog.visible" :close-on-click-modal="false" :before-close="resetTWmsReciptIntoLocPlanFormDialog" width="500px" append-to-body>
      <el-form ref="tWmsReciptIntoLocPlanForm" :model="tWmsReciptIntoLocPlanFormData" :rules="tWmsReciptIntoLocPlanFormRules" label-width="80px">
        <el-form-item label="容器号 " prop="contianBoxNo">
          <el-input v-model="tWmsReciptIntoLocPlanFormData.contianBoxNo" placeholder="请输入容器号 " />
        </el-form-item>
        <el-form-item label="要求出库时间" prop="requstRecptDate">
          <el-date-picker v-model="tWmsReciptIntoLocPlanFormData.requstRecptDate" type="date" value-format="yyyy-MM-dd" size="small" style="width: 100%" placeholder="选择要求出库时间" clearable />
        </el-form-item>
        <el-form-item label="库位号 " prop="locationNo">
          <el-input v-model="tWmsReciptIntoLocPlanFormData.locationNo" placeholder="请输入库位号 " />
        </el-form-item>
        <el-form-item label="" prop="materialName">
          <el-input v-model="tWmsReciptIntoLocPlanFormData.materialName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="customerName">
          <el-input v-model="tWmsReciptIntoLocPlanFormData.customerName" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="数量" prop="qty">
          <el-input v-model="tWmsReciptIntoLocPlanFormData.qty" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="入库计划明细号" prop="reciptLineId">
          <el-input v-model="tWmsReciptIntoLocPlanFormData.reciptLineId" placeholder="请输入入库计划明细号" />
        </el-form-item>
        <el-form-item label="上架序号" prop="seqNo">
          <el-input v-model="tWmsReciptIntoLocPlanFormData.seqNo" placeholder="请输入上架序号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmTWmsReciptIntoLocPlanFormDialog">确 定</el-button>
        <el-button @click="resetTWmsReciptIntoLocPlanFormDialog">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import TWmsReciptIntoLocPlanApi from '@/api/web/TWmsReciptIntoLocPlanApi'

const defaultTWmsReciptIntoLocPlanFormData = {
  contianBoxNo: null,
  requstRecptDate: null,
  locationNo: null,
  materialName: null,
  customerName: null,
  qty: null,
  reciptLineId: null,
  seqNo: null,
}
export default {
  name: 'TWmsReciptIntoLocPlanList',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      queryParams: {
        contianBoxNo: null,
        requstRecptDate: null,
        locationNo: null,
        materialName: null,
        customerName: null,
        qty: null,
        reciptLineId: null,
        seqNo: null,
        createTime: null,
        isValid: this.$constant.Y
      },
      page: {
        current: 1,
        pageSize: 10,
        total: 0,
        records: []
      },
      tWmsReciptIntoLocPlanFormDialog: {
        title: '',
        visible: false
      },
      tWmsReciptIntoLocPlanFormData: Object.assign({}, defaultTWmsReciptIntoLocPlanFormData),
      tWmsReciptIntoLocPlanFormRules: {
      },
      loading: true,
      searchVisible: true,
      multipleSelection: [],
      isSingle: true,
      isMultiple: true
    }
  },
  created() {
    this.queryParams.createTime = this.$route.query.createTime
    this.handleQuery()
    this.loadOptions()
  },
  methods: {
    loadOptions() {
    },
    handleAdd() {
      this.openTWmsReciptIntoLocPlanFormDialog()
    },
    handleRemove(row) {
      const ids = row.id || this.multipleSelection.map(item => item.id)
      this.$confirm('是否确认删除数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWmsReciptIntoLocPlanApi.remove(ids)
      }).then(() => {
        this.handleQuery()
        this.$message.success('删除成功')
      })
    },
    handleEdit(row) {
      const id = row.id || this.multipleSelection.map(item => item.id)[0]
      this.openTWmsReciptIntoLocPlanFormDialog(id)
    },
    handleQuery() {
      this.loading = true
      TWmsReciptIntoLocPlanApi.page(this.queryParams, this.page).then(response => {
        this.page.records = response.data.records
        this.page.total = response.data.total
        this.loading = false
      }, () => {
        this.loading = false
      })
    },
    handleExport() {
      this.$confirm('是否确认导出数据?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return TWmsReciptIntoLocPlanApi.exportData(this.queryParams)
      }).then(response => {
        this.$common.download(response.msg)
      })
    },
    openTWmsReciptIntoLocPlanFormDialog(id) {
      this.tWmsReciptIntoLocPlanFormDialog.visible = true
      if (id) {
        this.tWmsReciptIntoLocPlanFormDialog.title = '上架计划-修改'
        TWmsReciptIntoLocPlanApi.get(id).then(response => {
          this.tWmsReciptIntoLocPlanFormData = {
            ...this.tWmsReciptIntoLocPlanFormData,
            ...response.data
          }
        })
      } else {
        this.tWmsReciptIntoLocPlanFormDialog.title = '上架计划-添加'
      }
    },
    confirmTWmsReciptIntoLocPlanFormDialog() {
      this.$refs['tWmsReciptIntoLocPlanForm'].validate(valid => {
        if (valid) {
          if (this.tWmsReciptIntoLocPlanFormData.id) {
            TWmsReciptIntoLocPlanApi.edit(this.tWmsReciptIntoLocPlanFormData).then(response => {
              this.$message.success('修改成功')
              this.resetTWmsReciptIntoLocPlanFormDialog()
              this.handleQuery()
            })
          } else {
            TWmsReciptIntoLocPlanApi.add(this.tWmsReciptIntoLocPlanFormData).then(response => {
              this.$message.success('添加成功')
              this.resetTWmsReciptIntoLocPlanFormDialog()
              this.handleQuery()
            })
          }
        }
      })
    },
    resetTWmsReciptIntoLocPlanFormDialog() {
      this.tWmsReciptIntoLocPlanFormDialog = {
        title: '',
        visible: false
      }
      this.tWmsReciptIntoLocPlanFormData = Object.assign({}, defaultTWmsReciptIntoLocPlanFormData)
      this.resetForm('tWmsReciptIntoLocPlanForm')
    },
    handleSelectionChange(selection) {
      this.multipleSelection = selection
      this.isSingle = selection.length !== 1
      this.isMultiple = !selection.length
    },
    resetQuery() {
      this.page.current = 1
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
